package com.ycp.erp.view;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.adapter.ArrayWheelAdapter;
import com.contrarywind.view.WheelView;
import com.one.common.view.dialog.BaseDialog;
import com.ycp.erp.R;

import java.util.ArrayList;

/**
 * Class Des:
 * Created by bjh on 2021/9/3.
 */
public class SingleWeelviewDialog extends BaseDialog implements View.OnClickListener {
    private final WeelviewListener weelviewListener;
    private WheelView wheelview;
    private ArrayList<String> values;
    private int index;
    public SingleWeelviewDialog(Context context, ArrayList<String> values, WeelviewListener weelviewListener) {
        super(context, R.layout.layout_sex_weelview);
        this.weelviewListener=weelviewListener;
        this.values=values;
    }
    @Override
    public void initView() {
        super.initView();
        setShowBottom();
        TextView  tvCancel=view.findViewById(R.id.tvCancel);
        TextView tvConfirm = view.findViewById(R.id.tvConfirm);
        wheelview = view.findViewById(R.id.wheelview);
        tvCancel.setOnClickListener(this);
        tvConfirm.setOnClickListener(this);
        this.setCanceledOnTouchOutside(false);
        wheelview.setAdapter(new ArrayWheelAdapter(values));
        wheelview.setCyclic(false);
        wheelview.setLineSpacingMultiplier(2.8f);
        wheelview.setCurrentItem(0);
//        wheelview.setOnItemSelectedListener(new OnItemSelectedListener() {
//            @Override
//            public void onItemSelected(int index) {
//                SingleWeelviewDialog.this.index=index;
//            }
//        });
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tvCancel) {
            this.dismiss();
            weelviewListener.onCancel();
        } else if (v.getId() ==R.id.tvConfirm) {
            this.dismiss();
            weelviewListener.onItemSelected(wheelview.getCurrentItem());
        }
    }

    public interface WeelviewListener{
        void onCancel();
        void onItemSelected(int index);
    }
}
